package com.example.trackcircuitdiagnosis.time;

import java.io.DataInputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

public class ReadMnlDicData {
    private static String filePath="D:\\wechatfiles\\WeChat Files\\wxid_u11jgxkukq2o22\\FileStorage\\File\\2023-12\\山市20231219\\wjjc\\historydata\\2023-12-17\\mnldata\\MnlDic_New.dat";

    public static void main(String[] args) {
        ReadDecimalDatFile(filePath);

    }




    public static void ReadDecimalDatFile(String filePath) {
        int fileNum=1;
        try (DataInputStream dis = new DataInputStream(Files.newInputStream(Paths.get(filePath)))) {
            // 读取二进制数据
            byte[] buffer = new byte[1024];
            int bytesRead;

            bytesRead = dis.read(buffer);

            // 处理读取的数据
            for (int i = 0; i < bytesRead; i++) {
                // 先每四个字节一组输出
                if (i<12){
                    if (i % 4 == 0 && i > 0) {
                        System.out.println();
                    }
                    System.out.printf("%d ", buffer[i] & 0xFF);

                }else{
                    System.out.println();
                    int num=buffer[i] & 0xFF;
                    System.out.println("第"+fileNum+"文件名称长度为="+num);
                    i+=3;
                    StringBuilder utf8String = new StringBuilder();
                    for (int j = 1; j <= num; j++) {
                        int utfValue = buffer[i + j] & 0xFF;
                        utf8String.append((char) utfValue);

                    }
                    System.out.println("第"+fileNum+"文件名称为="+utf8String);

                    i+=num;
                    int utfValue=0;
                    for (int j = 0; j <4 ; j++) {
                        utfValue+= buffer[i + j] & 0xFF;
                    }
                    System.out.println("第"+fileNum+"文件序号为="+utfValue);
                    i+=4;
                    utfValue=0;
                    for (int j = 0; j <4 ; j++) {
                        utfValue+= buffer[i + j] & 0xFF;
                    }
                    System.out.println("第"+fileNum+"文件设备个数为="+utfValue);
                    i+=4;
                    utfValue=0;
                    for (int j = 0; j <4 ; j++) {
                        utfValue+= buffer[i + j] & 0xFF;
                    }
                    System.out.println("第"+fileNum+"文件模拟量频率为="+utfValue);

                    i+=4;
                    fileNum++;

                }


            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
